//页面初始加载
efform_onload = function() {
	var fdPlanStatus = decodeURI($("#fdPlanStatus").val());
	//隐藏/显示从表按钮
	if(fdPlanStatus != '草拟')
		hideAndShowSubButtons(false);
	else
		hideAndShowSubButtons(true);
}; 


/****************************从表操作******************************/

//从表新增按钮
button_insert_onclick = function (){
	if (isSelected("ef_grid_result") == 0)return; 
	var ei=_getEi();
	var eiBlock=ei.getBlock("result");
	
	var grid = efgrid.getGridObject("ef_grid_result");
	efgrid.submitForm("ef_grid_result", "ZM", "ZMCP13", "insert", true); 
}

//从表修改按钮
button_update_onclick = function (){
	if (isSelected("ef_grid_result") == 0)return; 
	efgrid.submitForm("ef_grid_result", "ZM", "ZMCP13", "update", true);
}

//从表删除按钮
button_delete_onclick = function (){
	var grid = isSelected("ef_grid_result");
	if (grid == 0) return;  
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r){
			efgrid.submitForm("ef_grid_result", "ZM", "ZMCP13", "delete", true);
		}
	}); 
} 

//新增、修改、删除后的执行方法
efgrid_onAjaxSubmitSuccess = function(gridId, service_name, method_name, eiInfo) {
	if (eiInfo.status != -1) {
		var grid = efgrid.getGridObject("ef_grid_result");
		grid.refresh( eiInfo );
		parent.refresh_main_grid();
	}
};

//从表单元格编辑后回调的方法
efgrid_onDataCellSaved = function( grid_id, row_index, col_index, cell_value ) 
{
	  var grid = efgrid.getGridObject( grid_id ); 
	  if( col_index == 1) 
	  { 
		  var info=_getEi();
		  var eiBlock=info.getBlock("cmes.cp.engineering");
		  for(var i=0;i<eiBlock.getRows().length;i++)
		  {
 			  var _value = eiBlock.getCell(i,"fdKeyId");
			  if(_value==cell_value)
			  {
				  var fdDepartmentId = eiBlock.getCell(i,"fdDepartmentId"); 		//施工部门ID
				  var fdBoringProcess = eiBlock.getCell(i,"fdBoringProcess");		//掘进方式
				  var fdClass = eiBlock.getCell(i,"fdClass");						//工程类别
				  var fdMineRockId = eiBlock.getCell(i,"fdMineRockId");				//煤岩类别
				  var fdSupportingTypeId = eiBlock.getCell(i,"fdSupportingTypeId");//支护方式
				  var fdRoadwayType = eiBlock.getCell(i,"fdRoadwayType");			//巷道用途
				  
				  grid.setCellValue(row_index, 2, fdDepartmentId, TYPE_DATA);
				  grid.setCellValue(row_index, 3, fdBoringProcess, TYPE_DATA);
				  grid.setCellValue(row_index, 5, fdClass, TYPE_DATA);
				  grid.setCellValue(row_index, 6, fdMineRockId, TYPE_DATA);
				  grid.setCellValue(row_index, 7, fdSupportingTypeId, TYPE_DATA);
				  grid.setCellValue(row_index, 8, fdRoadwayType, TYPE_DATA);
				  grid.refreshCell( row_index, 2 , TYPE_DATA );
				  grid.refreshCell( row_index, 3 , TYPE_DATA );
				  grid.refreshCell( row_index, 5 , TYPE_DATA );
				  grid.refreshCell( row_index, 6 , TYPE_DATA );
				  grid.refreshCell( row_index, 7 , TYPE_DATA );
				  grid.refreshCell( row_index, 8 , TYPE_DATA );
			  }
				  
		  }
	  } 
}

/*****************公用方法区******************/
//根据主表选中记录的状态，确定从表的按钮是否显示
var hideAndShowSubButtons=function(status)
{
	if(!status)
	{
		efbutton.setButtonStatus("insert", false);
		efbutton.setButtonStatus("update", false);
		efbutton.setButtonStatus("delete", false);
	}else
	{
		efbutton.setButtonStatus("insert", true);
		efbutton.setButtonStatus("update", true);
		efbutton.setButtonStatus("delete", true);
	}
}